import { defineStore } from "pinia";
import { Router } from "vue-router";
import teacherRoute from '@/router/teacher/route'
import { transAuthRouteToMenu, transMultiAuthRoutesToVueRoute } from "@/utils/router/menu";

interface RouteState {
    /** 是否添加过动态路由 */
    isAddedDynamicRoute: boolean;
    /** 路由首页name */
    // routeHomeName: AuthRoute.RouteKey;
    /** 菜单 */
    menus: GlobalMenuOption[];
}

export const useRouteStore = defineStore('route-store', {
    state: (): RouteState => ({
        isAddedDynamicRoute: false,
        menus: [],
    }),
    actions: {
        /**
         * 初始化动态路由
         * @param router 路由实例 等价于 $router
         */
        async initDynamicRoute(router: Router) {
            // console.log("所以，你甚至都没有进入初始动态路由 ");

            // debugger
            this.menus = transAuthRouteToMenu(teacherRoute)
            console.log("讲道理，我的menu应该没问题", this.menus);

            console.log("现在问题应该就是没有basic", teacherRoute);

            const vueRoutes = await transMultiAuthRoutesToVueRoute(teacherRoute);
            vueRoutes.forEach((route) => {
                console.log("循环遍历的route", route);

                router.addRoute(route)
            })

            console.log("初始化动态路由后--->", router, this.menus);

            // this.isAddedDynamicRoute = true
        },
    },
})